<template>
  <div class="component__combo_information_new" @click="toPath(detail.id)">
    <div class="information-left">
        <div class="information-name">{{detail.title}}</div>
        <div class="push-time">{{formatDate(detail.publishTime)}}</div>
    </div>
    <div class="information-right">
        <img v-if="detail.mainDiagram" :src="detail.mainDiagram" alt />
        <img v-else src="/img/mobile/news_default.png" alt />
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  props: ["detail"],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapState({
      is_ios(state) {
        return state.is_ios;
      },
      is_in_wechat(state) {
        return state.is_in_wechat;
      },
      member_discount(state) {
        return state.member_discount;
      },
      is_hidden_content(state) {
        return state.is_hidden_content;
      },
      is_wechat_ios_limit(state) {
        return state.is_wechat_ios_limit;
      }
    }),
    is_show_price() {
      if (this.is_wechat_ios_limit) {
        return this.is_ios && this.is_in_wechat;
      } else {
        return false;
      }
    }
  },
  watch: {},
  methods: {
      formatDate(timestamp) {
      let date = new Date(timestamp);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      let hour = date.getHours();
      let minute = date.getMinutes();
      let second = date.getSeconds();
      let add0 = (m) => {
        return m < 10 ? "0" + m : m;
      };
      let showTime = null;
      if (new Date(timestamp).toDateString() === new Date().toDateString()) {
        if (hour < 10) {
          showTime = "上午";
        } else if (hour < 12) {
          showTime = "中午";
        } else if (hour < 18) {
          showTime = "下午";
        } else {
          showTime = "晚上";
        }
        // console.log("今天", showTime + " " + add0(hour) + ":" + add0(minute));
        return showTime + " " + add0(hour) + ":" + add0(minute);
      } else {
        // console.log("以前", add0(year) + "/" + add0(month) + "/" + add0(day));
        return add0(year) + "/" + add0(month) + "/" + add0(day);
      }
    },
    toPath(id) {
      this.$router.push({
        path: "/m/information-detail",
        query: {
          id,
        },
      });
    },
  },
  created() {
    console.log(this.detail);
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>
.component__combo_information_new {
    width: 3.9456rem;
    height: 2.2656rem;
    border-radius: .192rem;
    overflow: hidden;
    padding: .384rem .288rem .4608rem;
    display: flex;
    justify-content: space-between;
    .information-left{
        width: 1.8rem;
        height: 1.344rem;
        .information-name{
            font-size: 0.2688rem;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 500;
            color: #333333;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            line-height: 0.384rem;
            height: 0.768rem;
            margin-bottom: .25rem;
        }
        .push-time{
            font-size: .2304rem;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #999999;
        }
    }
    .information-right{
        width: 1.344rem;
        height: 1.344rem;
        img{
            display: block;
            width: 100%;
            height: 100%;
            border-radius: .096rem;
            overflow: hidden;
        }
    }
}
</style>
<style lang="scss">
.component__combo_information_new {
}
</style>
